<template>
    <div class="header">
        <div class="logo">
            <img :src="baseURL + settingStore.current.logo" alt="">
            <span>{{ settingStore.current.logo_name }} · 管理系统</span>
        </div>
        <div class="user">
            <el-icon size="25" color="#E3E3E3">
                <User />
            </el-icon>
            <span>{{ userStore.userinfo.nickname }}</span>
            <!-- 退出登录 -->

            <el-tooltip content="退出登录" effect="dark">
                <el-icon size="20" color="#E3E3E3" @click="logout" class="logout">
                    <SwitchButton />
                </el-icon>
            </el-tooltip>

        </div>
    </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useUserStore } from '@/stores/useUser'
import { User, SwitchButton } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
import { baseURL } from '@/config/baseURL'
import { useSettingStore } from '@/stores/useSetting'

const router = useRouter()
const userStore = useUserStore()
const settingStore = useSettingStore()

const logout = () => {
    ElMessageBox.confirm('确定退出登录？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
        userStore.logout()
        sessionStorage.removeItem('token')
        sessionStorage.removeItem('userinfo')
        router.replace('/')
    })
}

</script>

<style scoped lang='less'>
.header {
    width: 100%;
    height: 60px;
    background-color: var(--primary-color);
    padding: 0 15px;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
    align-items: center;

    .logo {
        width: 300px;
        height: 60px;
        display: flex;
        align-items: center;
        color: #e3e3e3;
        user-select: none;
        cursor: pointer;

        img {
            height: 60%;
        }

        span {
            margin-left: 10px;
            font-size: 18px;
            letter-spacing: 1px;
        }
    }

    .user {
        color: #e3e3e3;
        display: flex;
        align-items: center;

        span {
            margin-left: 5px;
            font-size: 18px;
        }

        .logout {
            margin-left: 30px;
            cursor: pointer;
        }
    }
}
</style>